<?php 
class Somi_Form_RegisForm extends Zend_Form

      {

          public function init()

          {

              // Erstellt die Benutzer Subform: Benutzername und Passwort

              $user = new Zend_Form_SubForm();

              $user->addElements(array(

                  new Zend_Form_Element_Text('username', array(

                      'required'   => true,

                      'label'      => 'Benutzername:',

                      'filters'    => array('StringTrim', 'StringToLower'),

                      'validators' => array(

                          'Alnum',

                          array('Regex',

                                false,

                                array('/^[a-z][a-z0-9]{2,}$/'))

                      )

                  )),

       

                  new Zend_Form_Element_Password('password', array(

                      'required'   => true,

                      'label'      => 'Passwort:',

                      'filters'    => array('StringTrim'),

                      'validators' => array(

                          'NotEmpty',

                          array('StringLength', false, array(6))

                      )

                  )),

              ));

       

              // Erstellt die Demographische Subform: Vorname,

              // Familienname und Ort
 
              $demog = new Zend_Form_SubForm();

              $demog->addElements(array(

                  new Zend_Form_Element_Text('givenName', array(

                      'required'   => true,

                      'label'      => 'Vorname (erster):',
 
                      'filters'    => array('StringTrim'),
 
                      'validators' => array(

                          array('Regex',

                                false,
 
                                array('/^[a-z][a-z0-9., \'-]{2,}$/i'))
 
                      )
  
                  )),
  
       
 
                  new Zend_Form_Element_Text('familyName', array(
 
                      'required'   => true,

                      'label'      => 'Familienname (letzter):',

                      'filters'    => array('StringTrim'),

                      'validators' => array(

                          array('Regex',

                                false,

                                array('/^[a-z][a-z0-9., \'-]{2,}$/i'))

                      )

                  )),

       

                  new Zend_Form_Element_Text('location', array(

                      'required'   => true,

                      'label'      => 'Der eigene Ort:',

                      'filters'    => array('StringTrim'),

                      'validators' => array(

                          array('StringLength', false, array(2))

                      )

                  )),

              ));

       

              // Erstellt die Mailinglisten Subform

              $listOptions = array(

                  'none'        => 'keine Listen bitte',

                  'fw-general'  => 'Zend Framework General Liste',

                  'fw-mvc'      => 'Zend Framework MVC Liste',

                  'fw-auth'     => 'Zend Framework Authentication und ACL Liste',

                  'fw-services' => 'Zend Framework Web Services Liste',

              );

              $lists = new Zend_Form_SubForm();

              $lists->addElements(array(

                  new Zend_Form_Element_MultiCheckbox('subscriptions', array(

                      'label'        =>

                          'Welche Liste wollen Sie erhalten?',

                      'multiOptions' => $listOptions,

                      'required'     => true,

                      'filters'      => array('StringTrim'),

                      'validators'   => array(

                          array('InArray',

                                false,

                                array(array_keys($listOptions)))

                      )

                  )),

              ));

       

              // Die Subformen der Hauptform anhängen

              $this->addSubForms(array(

                  'user'  => $user,

                  'demog' => $demog,

                  'lists' => $lists

              ));
  
          }
          
          
 
/**

     * Eine Subform für die anzeige Vorbereiten

     *

     * @param  string|Zend_Form_SubForm $spec

     * @return Zend_Form_SubForm

     */

    public function prepareSubForm($spec)

    {

        if (is_string($spec)) {

            $subForm = $this->{$spec};

        } elseif ($spec instanceof Zend_Form_SubForm) {

            $subForm = $spec;

        } else {
			Zend_Session::namespaceUnset('RegisController');
            throw new Exception('Ungültiges Argument an ' .__FUNCTION__ . '() übergeben');
            

        }

        $this->setSubFormDecorators($subForm)

             ->addSubmitButton($subForm)

             ->addSubFormActions($subForm);

        return $subForm;

    }

 

    /**

     * Form Dekoratore zu einer individuellen Subform hinzufügen

     *

    * @param  Zend_Form_SubForm $subForm

     * @return My_Form_Registration

     */

    public function setSubFormDecorators(Zend_Form_SubForm $subForm)

    {

        $subForm->setDecorators(array(

            'FormElements',

            array('HtmlTag', array('tag' => 'dl',

                                   'class' => 'zend_form')),

            'Form',

        ));

        return $this;

    }

 

    /**

     * Einen Sendebutton in einer individuellen Subform hinzufügen

     *

     * @param  Zend_Form_SubForm $subForm

     * @return My_Form_Registration

     */

    public function addSubmitButton(Zend_Form_SubForm $subForm)

    {

        $subForm->addElement(new Zend_Form_Element_Submit(

            'save',

            array(

                'label'    => 'Speichern und Fortfahren',

                'required' => false,

                'ignore'   => true,

            )

        ));

        return $this;

    }

 

    /**

    * Aktion und Methode der Subform hinzufügen

     *

     * @param  Zend_Form_SubForm $subForm

     * @return My_Form_Registration

     */

    public function addSubFormActions(Zend_Form_SubForm $subForm)

    {

        $subForm->setAction('./regis/process/');

        $subForm->setMethod('post');
        return $this;

    }

}
 
 